package com.ely.coupon.activity.controller;

import com.ely.coupon.activity.api.CouponActivityApi;
import com.ely.coupon.activity.dto.CouponActivityDto;
import com.ely.coupon.activity.dto.CouponActivityInfo;
import com.ely.coupon.activity.service.CouponActivityService;
import com.ely.coupon.common.core.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/coupon/activity")
@Api(tags = "优惠卷活动管理平台Api接口")
public class CouponActivityController implements CouponActivityApi {
    @Resource
    private CouponActivityService couponActivityService;


    /**
     * 创建优惠券活动
     */
    @ApiOperation("创建优惠卷活动")
    @PostMapping("/create")
    public ResponseResult<Integer> create(@RequestBody @Validated CouponActivityDto couponActivityDto) {
        return ResponseResult.success(couponActivityService.create(couponActivityDto));
    }

    /**
     *
     */
    @ApiOperation("创建优惠卷活动")
    @PostMapping("/search")
    public ResponseResult<Integer> search(CouponActivityDto couponActivityDto) {
        return ResponseResult.success(couponActivityService.create(couponActivityDto));
    }

    /**
     * 多表查询
     *
     * @return
     */
    @ApiOperation("查看详细信息")
    @GetMapping("/detail/{couponActivityId}")
    public ResponseResult<Integer> detail(@PathVariable Long couponActivityId) {
        return ResponseResult.success(1);
    }

    /**
     * 如果是禁用, 用户领取的优惠券就失效
     *
     * @param status
     * @return
     */
    @ApiOperation("修改优惠卷活动的状态")
    @GetMapping("/del")
    public ResponseResult<Integer> del(int status) {
        return ResponseResult.success(1);
    }

    @ApiOperation("查看详细信息")
    @Override
    public ResponseResult<CouponActivityInfo> getCouponActivityInfo(@RequestParam Long couponActivityId) {
        return ResponseResult.success(couponActivityService.getCouponActivityInfo(couponActivityId));
    }

    @ApiOperation("减少优惠卷")
    @Override
    public ResponseResult<Integer> decrease(@RequestParam Long couponActivityId, @RequestParam Integer quantity) {
        return ResponseResult.success(couponActivityService.decrease(couponActivityId, quantity));
    }

    @ApiOperation("根据类型获取优惠券")
    @Override
    public ResponseResult<CouponActivityInfo> getNewCouponInfo(@RequestParam Integer type) {
        return ResponseResult.success(couponActivityService.getNewCouponInfo(type));
    }


}
